import {
	exitRoomMember,
	updateLiveRoomInfo,
	roomMemberPage,
	liveRoomInfoById
} from "@/apis/tz/api.js"
import {
	getUserInfo
} from "@/handleScript/handle.js";
export function init(id, that) {
	return new Promise(async (resv, rej) => {
	 await getUserInfo()
		let res = await liveRoomInfoById({
			id: id
		});
		if (res.code != 0) {
			that.$toast(res.msg)
			setTimeout(() => {
				uni.reLaunch({
					url: "pages/liveRoomList/liveRoomList"
				})
			}, 2000)
		}
		//先获取roomMemberId
		let r = await roomMemberPage({
			pageNo: 1,
			pageSize: 100,
			roomId: id,
			memberUserId: that.userInfo.userId,
		})

		if (r.code == 0 && r.data.list.length > 0) {

			that.$tn.vuex("liveRoom", Object.assign(r.data.list[0], res.data));
			that.roomMemberId = r.data.list[0].roomMemberId;
			that.liveRoom.roomTitleFlag = that.liveRoom.roomTitleFlag == 'Y';
			that.liveRoom.roomStatus = that.liveRoom.roomStatus == 'Y';
			that.liveRoom.compereManagerAuthorityFlag = that.liveRoom.compereManagerAuthorityFlag == 'Y';


		} else {
			that.$toast(r.msg)
			setTimeout(() => {
				uni.reLaunch({
					url: "pages/liveRoomList/liveRoomList"
				})
			}, 2000)
		}
		resv()
	})

}